import { StatusCode } from "@/code";
import { BaseOpt, CamData } from "@/types";
import { useModule } from "../createMod";
import { TakePicture } from "../modeFunc/takePictureStep";
import { getCallBackParam } from "../utils";
let imageFileId = 0;
export function getCamera(opt: BaseOpt<CamData | null>) {
    let imageFileIdSave = imageFileId;
    const io = useModule();
    const { common } = io;
    if (!common) {
      opt.fail(getCallBackParam(StatusCode.NoModules));
      return;
    }
    TakePicture({mod: 'cam'},imageFileId.toString()).then((ret) => {
      if (ret === "TakePictureSuccess") {
        let path = `c:\\camera\\CustomerImg${imageFileIdSave}.jpg`;
        common.ReadImageBase64(path).then((BASE64) => {
          opt.success(getCallBackParam(StatusCode.Success,{
            file: BASE64,
            filename: path,
          }))
        });
      } else {
        opt.fail(getCallBackParam(StatusCode.hTakePictureFail));
      }
    });
    imageFileId++;
  }